package com.kingwang.study.spring.security.demo.security.config;

import com.kingwang.study.spring.security.demo.security.token.session.TokenSessionManager;
import com.kingwang.study.spring.security.demo.security.token.session.impl.InMemoryTokenSessionManager;
import com.kingwang.study.spring.security.demo.util.CurrentDateTimeGenerator;
import com.kingwang.study.spring.security.demo.util.DateTimeGenerator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 使用到的非Spring Component的Bean
 */
@Configuration
public class BeanConfig {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Bean
    public DateTimeGenerator dateTimeGenerator() {
        return new CurrentDateTimeGenerator();
    }

    @Bean
    public TokenSessionManager tokenSessionManager(TokenSessionConfig tokenSessionConfig, DateTimeGenerator dateTimeGenerator) {
        return new InMemoryTokenSessionManager(tokenSessionConfig, dateTimeGenerator);
    }
}
